﻿using B.S.ProductionProject.Domain;
using B.S.ProductionProject.ErrorCode;
using B.S.ProductionProject.Read.WebAPI.Applications.Commands.ProductionScheduleDetailCommand;
using MediatR;
using SqlSugar;

namespace B.S.ProductionProject.Read.WebAPI.Applications.CommandHandlers.ProductionScheduleDetailCommandHandler
{
    public class GetBYIdProductionScheduleDetailCommandHandler : IRequestHandler<GetBYIdProductionScheduleDetailCommand, APIResult<List<ProductionScheduleDetail>>>
    {
        private readonly ISqlSugarClient db;

        public GetBYIdProductionScheduleDetailCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<APIResult<List<ProductionScheduleDetail>>> Handle(GetBYIdProductionScheduleDetailCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProductionScheduleDetail>> result = new APIResult<List<ProductionScheduleDetail>>();
            result.code = APIResultCode.success;
            result.msg = "获取成功";

            var list = await db.Queryable<ProductionScheduleDetail>().Where(p => p.isDelete == false && p.ProductionPlanningId == request.ProductionPlanningId).ToListAsync();

            result.data = list;

            return await Task.FromResult(result);
        }
    }
}
